package cn.interestingshop.servlet;

import cn.interestingshop.model.entity.BaseOrder;
import cn.interestingshop.service.BaseOrderService;
import cn.interestingshop.service.BaseOrderServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "BaseOrderServlet", urlPatterns = "/BaseOrderServlet")
public class BaseOrderServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    BaseOrderService service = new BaseOrderServiceImpl();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String action = "";

        switch (action) {
            case "baseOrder" :
                baseOrder(request, response);
                break;
        }
    }

    public void baseOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String account = request.getParameter("account");

        BaseOrder baseOrder = service.getBaseOrderByAccount(account);

        String order = JSON.toJSONString(baseOrder);

        PrintWriter out = response.getWriter();

        out.print(order);
        out.flush();
        out.close();
    }
}